# encoding: utf-8

# python -m pwiz -e mysql -H 192.168.0.229 -p 4706 -u ddcollect -P dspt > testModel229_dp.py

from peewee import *



# 此方法可避免错误 （2006, 'MySQL server has gone away'），解决peewee无法维持长连接的问题 （start） ---------------------
from peewee import __exception_wrapper__
class RetryOperationalError(object):
    def execute_sql(self, sql, params=None, commit=True):
        try:
            cursor = super(RetryOperationalError, self).execute_sql(sql, params, commit)
        except OperationalError:
            if not self.is_closed():
                self.close()
            with __exception_wrapper__:
                cursor = self.cursor()
                cursor.execute(sql, params or ())
                if commit and not self.in_transaction():
                    self.commit()
        return cursor
class RetryMySQLDatabase(RetryOperationalError, MySQLDatabase):
    pass
database = RetryMySQLDatabase('dspt', **{'charset': 'utf8', 'sql_mode': 'PIPES_AS_CONCAT', 'use_unicode': True, 'host': '192.168.0.229', 'port': 4706, 'user': 'ddcollect', 'passwd': 'Cx_123456'})
# 此方法可避免错误 （2006, 'MySQL server has gone away'），解决peewee无法维持长连接的问题 （end） ---------------------


class UnknownField(TextField):
    pass


class BaseModel(Model):
    class Meta:
        database = database


class Spider(BaseModel):
    cur_cate = IntegerField(null=True)
    cur_page = IntegerField(null=True)
    exe_sum = IntegerField(null=True)
    group_code = CharField()
    lib_type = CharField()
    name = CharField()
    pid = IntegerField(null=True)
    script = CharField(null=True)
    status = IntegerField()
    suc_num = IntegerField(null=True)
    sup_num = IntegerField(null=True)
    progress = IntegerField(null=True)
    value = IntegerField(null=True)
    model = IntegerField(null=True)
    start_time = DateTimeField(null=True)
    end_time = DateTimeField(null=True)
    cur_ip = CharField(null=True)
    repeat_like_num = IntegerField(null=True)
    detail_page = CharField(null=True)

    class Meta:
        table_name = 'spider'

